<template>
  <div class='container'>
    <img src='/static/images/1.png' class='tuoyuan'/>
    <div class='commentCon'>
        <textarea class="weui-textarea"  :placeholder="type==1?comment:reply" @change="onchange" :value="content" v-model="form.value" maxlength="-1"/>
        <div class='btn' @click='toComment' v-if="type==1">发表</div>
        <div class='btn' @click='toComment' v-else>回复</div>
    </div>
  </div>
</template>

<script>
import {comment} from "@/api/operate"
export default {
  components: {

  },

  data () {
    return {
       index:"111",
       type:"",
       comment:"写评论...",
       reply:"回复...",
       info:"",
       content:"",
       form:{
         value:""
       },
       actType:"",
    }
  },
  methods:{
     toComment(){
       console.log(this.form)
        let data={};  
        if(this.type==1){
           data.article_id=this.info.id;
           if(this.info.article_type){
               data.type=this.info.article_type;
           }else{
               data.type=this.info.type;
           }
            
        }else{
           data.article_id=this.info.article_id; 
           data.comment_id=this.info.id; 
           data.type=this.actType 
        }
        data.model=this.type;   
        data.content=this.form.value;   
        if(this.form.value.length!=0) {
           comment(data).then(res=>{
             if(res.code==200){
                  wx.navigateBack({
                    delta: 1
                  });
             }
            
          })
        }else{
          wx.showToast({
             title: '请填写评论',
             icon:"none"
           });
        }
        
     },
     onchange(e){
        // this.content=e.mp.detail.value;
     }
  },
  created () {
    
  },
  
  onLoad(options){
     Object.assign(this.$data, this.$options.data())
      console.log(options)
      this.info=JSON.parse(options.info)
      this.type=options.type;
      if(options.actType){
        this.actType=options.actType;
      }
  },
  onUnload(){
      console.log("我已经离开了！");
     
  }
  
}
</script>
<style lang="scss" scoped>
page{
  background: #F4F5F5;
}
.tuoyuan{
  width: 375px;
  height: 118px;
  display: block;
  position: absolute;
  top: 0;
  left: 0;
}
.container{
  padding: 15px;
}
.commentCon{
  width:345px;
  min-height: 322px;
  background:rgba(255,255,255,1);
  box-shadow:0px 2px 8px 0px rgba(0, 0, 0, 0.14);
  border-radius:7px;
  position: relative;
  z-index: 2;
  font-size:14px;
  font-weight:500;
  color:rgba(153,153,153,1);
}
.commentCon textarea{
  padding: 15px;
  box-sizing: border-box;
  min-height: 280px;
}
.commentCon .btn{
  position: absolute;
  width:345px;
  height:45px;
  background:#1A84FB;
  border-radius:5px;
  text-align: center;
  line-height: 45px;
  font-size:15px;
  font-weight:bold;
  color:rgba(255,255,255,1);
  left: 0;
  bottom: 0;
}
</style>
